home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / MacShell / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-04  |  3.2 KB  |  147 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        MacShell
  5. ** File:        help.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "MacShell.h"            /* Get the MacShell includes/typedefs, etc.    */
  19. #include "MacShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "MacShell.protos"        /* Get the prototypes for MacShell.            */
  21.  
  22. #ifndef __BALLOONS__
  23. #include <Balloons.h>
  24. #endif
  25.  
  26. #ifndef __PROCESSES__
  27. #include <Processes.h>
  28. #endif
  29.  
  30. #ifdef THINK_C
  31. #include "Utilities.h"
  32. #else
  33. #ifndef __UTILITIES__
  34. #include <Utilities.h>
  35. #endif
  36. #endif
  37.  
  38.  
  39.  
  40. /*****************************************************************************/
  41. /*****************************************************************************/
  42.  
  43.  
  44.  
  45. #pragma segment Main
  46. void    DynamicBalloonHelp(void)
  47. {
  48.     WindowPtr            window, oldPort;
  49.     ProcessSerialNumber    cpsn, fpsn;
  50.     FileRecHndl            frHndl;
  51.     Point                mouseLoc, tip;
  52.     ControlHandle        ctl;
  53.     Rect                rct;
  54.     short                part, message, pos;
  55.     HMMessageRecord        helpMessage;
  56.     Boolean                procsSame;
  57.     static short        lastMessage;
  58.     static short        position[4] = {5, 6, 2, 1};
  59. #if MACSHELL_VERSION
  60.     TEHandle            teHndl;
  61. #endif
  62.  
  63.     if (gSystemVersion < 0x0700) return;
  64.         /* The system can't support balloons. */
  65.  
  66.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  67.         lastMessage = 0;
  68.         return;
  69.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  70.  
  71.     HMGetBalloonWindow(&window);
  72.     if (!window) lastMessage = 0;
  73.         /* There is no balloon currently, so there is no last message. */
  74.  
  75.     tip = mouseLoc = GetGlobalMouse();
  76.     part = FindWindow(mouseLoc, &window);
  77.     if ((window != FrontWindow()) || (part != inContent)) {
  78.         lastMessage = 0;
  79.         return;
  80.     }        /* We aren't over the content of the front window, so leave. */
  81.  
  82.     GetCurrentProcess(&cpsn);
  83.     GetFrontProcess(&fpsn);
  84.     SameProcess(&cpsn, &fpsn, &procsSame);
  85.     if (!procsSame) {
  86.         lastMessage = 0;
  87.         return;
  88.     }        /* We aren't the front process, so leave. */
  89.  
  90.     GetPort(&oldPort);
  91.     frHndl = (FileRecHndl)GetWRefCon(window);
  92.     SetPort(window);
  93.     GlobalToLocal(&mouseLoc);
  94.  
  95.     ctl = ((WindowPeek)window)->controlList;
  96.     while (ctl) {
  97.         rct = (*ctl)->contrlRect;
  98.         if (PtInRect(mouseLoc, &rct)) break;
  99.         ctl = (*ctl)->nextControl;
  100.     }        /* Find the control that we are over. */
  101.  
  102.     message = 0;
  103.     if (ctl) {
  104.  
  105. #if MACSHELL_VERSION
  106.  
  107.         teHndl = (TEHandle)GetCRefCon(ctl);
  108.         if (teHndl == (*frHndl)->doc.inBox)  message = 2;
  109.         if (teHndl == (*frHndl)->doc.outBox) message = 4;
  110.  
  111. #endif
  112.  
  113.     }
  114.  
  115.     if (message) {
  116.  
  117. #if MACSHELL_VERSION
  118.  
  119.         if ((*frHndl)->connect.connected) --message;
  120.  
  121. #endif
  122.  
  123.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  124.             lastMessage = message;
  125.             helpMessage.hmmHelpType             = khmmStringRes;
  126.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  127.             helpMessage.u.hmmStringRes.hmmIndex = message;
  128.             LocalToGlobalRect(&rct);
  129.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  130.             if (tip.h > (rct.left + rct.right) / 2) ++pos;
  131.             pos = position[pos];
  132.             SetOrigin(0, 0);
  133.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  134.         }
  135.     }
  136.     else {
  137.         if (lastMessage) HMRemoveBalloon();
  138.         lastMessage = 0;
  139.     }
  140.  
  141.     SetOrigin(0, 0);
  142.     SetPort(oldPort);
  143. }
  144.  
  145.  
  146.  
  147.